function LeaderboardContent({ scores, playerName, gameStarted, currentLevel, onScoreClick }) {
    const getUniqueScores = (scores) => {
        try {
            const uniqueScores = {};
            scores.forEach(score => {
                const playerName = score.objectData.playerName.toLowerCase();
                if (!uniqueScores[playerName] || uniqueScores[playerName].objectData.score < score.objectData.score) {
                    uniqueScores[playerName] = score;
                }
            });
            return Object.values(uniqueScores).sort((a, b) => {
                if (b.objectData.score !== a.objectData.score) {
                    return b.objectData.score - a.objectData.score;
                }
                return new Date(b.objectData.timestamp) - new Date(a.objectData.timestamp);
            });
        } catch (error) {
            reportError(error);
            return [];
        }
    };

    const getDisplayScores = (allScores) => {
        try {
            if (!gameStarted) {
                return allScores.slice(0, 100).map((score, index) => ({
                    ...score,
                    position: index + 1
                }));
            }

            const filteredScores = allScores.filter(score => 
                score.objectData.playerName.toLowerCase() !== playerName.toLowerCase()
            );

            const virtualScore = {
                objectId: 'current',
                objectType: 'colorGameScore',
                objectData: {
                    playerName: playerName,
                    score: currentLevel
                },
                isCurrentPlayer: true
            };

            const combinedScores = [...filteredScores, virtualScore].sort((a, b) => {
                if (b.objectData.score !== a.objectData.score) {
                    return b.objectData.score - a.objectData.score;
                }
                if (a.isCurrentPlayer) return -1;
                if (b.isCurrentPlayer) return 1;
                return 0;
            });

            const virtualPosition = combinedScores.findIndex(score => score.isCurrentPlayer) + 1;
            virtualScore.position = virtualPosition;

            let relevantScores = [];

            if (virtualPosition === 1) {
                relevantScores.push(virtualScore);
                if (combinedScores.length > 1) {
                    relevantScores.push({
                        ...combinedScores[1],
                        position: 2,
                        showDividerBefore: true,
                        showEllipsisAfter: true
                    });
                }
            } else if (virtualPosition === 2) {
                relevantScores.push({
                    ...combinedScores[0],
                    position: 1
                });
                relevantScores.push({
                    ...virtualScore,
                    showDividerBefore: true
                });
            } else {
                relevantScores.push({
                    ...combinedScores[0],
                    position: 1,
                    showEllipsisAfter: true
                });
                
                if (virtualPosition > 2) {
                    relevantScores.push({
                        ...combinedScores[virtualPosition - 2],
                        position: virtualPosition - 1
                    });
                }
                
                relevantScores.push({
                    ...virtualScore,
                    showDividerBefore: true
                });
            }

            return relevantScores;
        } catch (error) {
            reportError(error);
            return [];
        }
    };

    const uniqueScores = getUniqueScores(scores);
    const displayScores = getDisplayScores(uniqueScores);

    return (
        <div className="space-y-2 p-4" data-name="leaderboard-list">
            {displayScores.map((score) => (
                <LeaderboardItem 
                    key={score.objectId} 
                    score={score} 
                    onScoreClick={onScoreClick}
                />
            ))}
            
            {displayScores.length === 0 && (
                <p className="text-center text-gray-500 dark:text-gray-400" data-name="no-scores">
                    No scores yet
                </p>
            )}
        </div>
    );
}
